package array;

import org.junit.Before;
import org.junit.Test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

public class ArraysUtils {


    @Test
    public void func() {
        StringBuilder stringBuilder = new StringBuilder("123");
        System.out.println(stringBuilder.deleteCharAt(stringBuilder.length()-1));
    }

    @Test
    public void func2() {
        System.out.println("hello");
    }

    private String str = "12345";

    String[] map = {"abc", "def", "ghi", "jkl", "mno", "pqrs", "tuv", "wxyz"};
    List<String> list = new ArrayList<>();
    StringBuilder sb = new StringBuilder();

    @Test
    public void func1() {
        String str = "232";
        backTrace(0, str);
        System.out.println(list);
    }

    private void backTrace(int index, String inputNumStr) {
        if (index == inputNumStr.length()) {
            list.add(sb.toString());
            return;
        }
        String strFromKey = map[inputNumStr.charAt(index) - '2'];
        for (char ch : strFromKey.toCharArray()) {
            sb.append(ch);
            backTrace(index+1,inputNumStr);
            sb.deleteCharAt( sb.length()-1 );
        }
    }
}
